package com.aiwu.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

/**
 * 拦截触摸事件
 */
public class TouchLinearLayout extends LinearLayout {
    private boolean interceptTouch;

    public TouchLinearLayout(Context context) {
        super(context);
    }

    public TouchLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public TouchLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public boolean isInterceptTouch() {
        return interceptTouch;
    }

    public void setInterceptTouch(boolean interceptTouch) {
        this.interceptTouch = interceptTouch;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (interceptTouch) {
            return true;
        }
        return super.dispatchTouchEvent(ev);
    }
}
